module ProjectSystem
protected  
  def current_project
    @current_project ||= (get_project_from_session) # unless @current_project == false
  end

  def project_required
    @user = current_user
    @project = current_project
  end

  def current_project=(new_project)
    session[:project_id] = (new_project ? new_project.id : nil)
    @current_project = new_project || false
  end

  # Called from #current_project.
  def get_project_from_session
    self.current_project = Project.find_by_id(session[:project_id]) if session[:project_id]
  end
    
  def self.included(base)
    base.send :helper_method, :current_project
  end    
    
end
